package com.warm.pump.frame.db;


import com.warm.pump.frame.db.impl.DruidWrapper;

/**
 * Created by guozj on 2017/10/12.
 * 用枚举代替工厂类，实现不同数据源实现类的
 */
public enum DataSourceEnum {

    DRUID("druid", new DruidWrapper());
    private String title;
    private DataSourceWrapper dataSourceWrapper;

    DataSourceEnum(String title, DataSourceWrapper dataSourceWrapper) {
        this.title = title;
        this.dataSourceWrapper = dataSourceWrapper;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public DataSourceWrapper getDataSourceWrapper() {
        return dataSourceWrapper;
    }

    public void setDataSourceWrapper(DataSourceWrapper dataSourceWrapper) {
        this.dataSourceWrapper = dataSourceWrapper;
    }

    public static DataSourceWrapper match(String name, DataSourceEnum defaultWrapper) {
        if (name != null) {
            for (DataSourceEnum item : DataSourceEnum.values()) {
                if (item.name().equals(name)) {
                    return item.getDataSourceWrapper();
                }
            }
        }
        return defaultWrapper.getDataSourceWrapper();
    }
}
